<template>
  <div class="nav-header">
    <el-icon :size="35" class="el-icon" @click="handleFoldClick">
      <!-- 动态组件 加载不同图标 -->
      <component :is="isFold ? Expand : Fold"></component>
    </el-icon>
    <div class="content">
      <div class="breadcrumb">
        <NavBreadcrumb :breadcrumbs="breadcrumbs"></NavBreadcrumb>
      </div>
      <div class="user-info">
        <UserInfo></UserInfo>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import UserInfo from './UserInfo.vue'
import NavBreadcrumb from '@/base-ui/breadcrumb/Breadcrumb.vue'
import { Expand, Fold } from '@element-plus/icons-vue'

import { useLoginStore } from '@/store/modules/login'
import { pathMapBreadcrumbs } from '@/utils/mapMenus'
//是否需要折叠 默认不需要
const isFold = ref(false)
const emit = defineEmits(['foldChange'])
const handleFoldClick = () => {
  isFold.value = !isFold.value
  emit('foldChange', isFold.value)
}

// 面包屑的数据 用计算属性监听到每次点击的变化
const breadcrumbs = computed(() => {
  return pathMapBreadcrumbs(useLoginStore().userMenus, useRoute().path)
})
</script>
<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;
  .el-icon {
    cursor: pointer;
    margin-right: 10px;
  }
  .content {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
